class Solution {
public:
    int maxProfit(vector<int>& prices) {
        
        int low1, low2, high;
        low1 = low2 = high = 0;
        if(prices.size() <= 1) return 0;
        for(int i=1; i<prices.size(); ++i)
        {
            if(prices[i] < prices[low1])
            {
                low1 = i;
            }
            
            if(prices[i] - prices[low1] > prices[high] - prices[low2])
            {
                high = i;
                low2 = low1;
            }
        }
        return prices[high] - prices[low2] ;
    }
};
